package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.RadarLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author:let_free
 * @Date:2024/9/18/14:49
 **/
@RestController
@Slf4j
@RequestMapping("/radarLog")
@Api(tags = "雷达日志")
public class RadarLogController {
    @Autowired
    private RadarLogService radarLogService;

    /**
     * @return luo.utils.AjaxResult
     * @description 获取最新的到达的雷达基文件的时间戳（加八小时之后的结果）以及未来20帧的文件名
     * @author let_free
     * @date 2024/10/1 14:16
     */
    @GetMapping("/getPredictionName")
    @ApiOperation(value = "获取雷达预测文件名")
    public AjaxResult getLatestLog() throws ParseException {
        String filename = radarLogService.getLatestName();
        List<String> nameList = new ArrayList<>();
        if (filename != null) {
            nameList = radarLogService.getFuture20Name("", filename, "png", 20);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("nameList", nameList);
        map.put("currentName", filename);
        return AjaxResult.success(map);
    }

    @GetMapping("/getPredictionNameWithCurrentName")
    @ApiOperation(value = "获取雷达预测文件名")
    public AjaxResult getLatestLog2() throws ParseException {
        String filename = radarLogService.getLatestName();
        List<String> nameList = new ArrayList<>();
        if (filename != null) {
            nameList = radarLogService.getFuture20Name("", filename, "png", 20);
        }
        nameList.add(0, filename);
        Map<String, Object> map = new HashMap<>();
        map.put("nameList", nameList);
        map.put("currentName", filename);
        return AjaxResult.success(map);
    }

    /**
     * @return com.ruoyi.common.core.domain.AjaxResult
     * @description 获取最新的雷达文件名称
     * @author let_free
     * @date 2024/11/20 15:40
     */
    @GetMapping("/getLatestName")
    public AjaxResult getLatestName() {
        String filename = radarLogService.getLatestName();
        return AjaxResult.success(filename);
    }

    @GetMapping("/getByTime")
    public AjaxResult getByTime(@RequestParam("date") String fileTime) {
        return AjaxResult.success(radarLogService.getByTime(fileTime));
    }
}
